'use strict';
import React, {Component} from 'react';
import {
    Alert,
    Platform,
} from 'react-native';
import * as types from '../constants/action-types';

import Http from '../core/utils/http';
import API from '../constants/server-apis';
import InitDB from '../core/database/init-db';
import Util from '../core/utils/util';

//附近动态
export function near(cfg) {
    return dispatch => {
        const params = Object.assign({
            objId:'circleNearList',
            lat:"40.0497810000",
            lng:"116.3424590000",
            pageNo:"1",
            pageSize:"10"
        },cfg);
        return Http.fetch(API.API_DONG_TAI_NEAR_URL, params).then(json=>{
            if(json && json.hasOwnProperty('circleNearList')){
                dispatch(receiveNear(json.circleNearList))
            }
            return json;
        })
    }
}

function fetchNear() {
    return {
        type: types.FETCH_DONG_TAI_NEAR_RESULT,
    };
}

function receiveNear(near) {
    return {
        type: types.RECEIVE_DONG_TAI_NEAR_RESULT,
        near: near,
    };
}


//热门动态
export function hot(cfg) {
    return dispatch => {
        const params = Object.assign({
            objId:'circleNewList',
            lat:"40.0497810000",
            lng:"116.3424590000",
            pageNo:"1",
            pageSize:"10"
        },cfg);
        return Http.fetch(API.API_DONG_TAI_HOT_URL, params).then(json=>{
            if(json && json.hasOwnProperty('circleNewList')){
                dispatch(receiveHot(json.circleNewList))
            }
            return json;
        })
    }
}

function fetchHot() {
    return {
        type: types.FETCH_DONG_TAI_HOT_RESULT,
    };
}

function receiveHot(hot) {
    return {
        type: types.RECEIVE_DONG_TAI_HOT_RESULT,
        hot: hot,
    };
}


//关注动态
export function focus(cfg) {
    return dispatch => {
        const params = Object.assign({
            objId:'circleFocusList',
            pageNo:"1",
            pageSize:"10"
        },cfg);
        return Http.fetch(API.API_DONG_TAI_FOCUS_URL, params).then(json=>{
            if(json && json.hasOwnProperty('circleFocusList')){
                dispatch(receiveFocus(json.circleFocusList))
            }
            return json;
        })
    }
}

function fetchFocus() {
    return {
        type: types.FETCH_DONG_TAI_FOCUS_RESULT,
    };
}

function receiveFocus(focus) {
    return {
        type: types.RECEIVE_DONG_TAI_FOCUS_RESULT,
        focus: focus,
    };
}


